<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增展会分类')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-eventsort-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">展会分类名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sortName" id="sortName" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">

    $("#form-eventsort-add").validate({
        rules:{
            onkeyup: false,
            sortName:{
                remote: {
                    url: ctx + "system/eventsort/checkSortNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "sortName" : function() {
                            return $.common.trim($("#sortName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "sortName": {
                remote: "展会分类名称已经存在"
            }
        },
        focusCleanup: true
    });

    $('input').on('ifChanged', function(obj){
        var type = $(this).val();
        var checked = obj.currentTarget.checked;
        if (type == 1) {
            if (checked) {
                $._tree.expandAll(true);
            } else {
                $._tree.expandAll(false);
            }
        } else if (type == "2") {
            if (checked) {
                $._tree.checkAllNodes(true);
            } else {
                $._tree.checkAllNodes(false);
            }
        } else if (type == "3") {
            if (checked) {
                $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
            } else {
                $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
            }
        }
    })

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }

    function add() {
        var sortName = $("input[name='sortName']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "system/eventsort/add",
            data : {
                "sortName": sortName
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>